/*
* @Author: liyanweiofwin
* @Date:   2017-06-18 17:11:16
* @Last Modified by:   liyanweiofwin
* @Last Modified time: 2017-06-18 19:36:21
*/

'use strict';
require('./index.css');

var _mm 		  = require('util/mm.js');
var templateIndex = require('./index.string');

var navSide = {
	option :{
		name :"",
		navList:[
			{name :'user-center',desc:'个人中心',href:'./user-center.html'},
			{name :'order-list',desc:'我的订单',href:'./order-list.html'},
			{name :'pass-update',desc:'修改密码',href:'./pass-update.html'},
			{name :'about',desc:'关于MMall',href:'./about.html'}
		]
	},
	init : function (option){
		// 合并选项
		$.extend(this.option,option);
		this.renderNav();
	},
	renderNav :function(){
		// 计算active数据
		for (var i = 0,iLengrh = this.option.navList.length;i<iLengrh;i++) {
			if (this.option.navList[i].name === this.option.name) {
				this.option.navList[i].isActive = true;
			}
		};

		var navHtml = _mm.renderHtml(templateIndex ,{
			navList : this.option.navList
		});
		// put html into continer
		$('.nav-side').html(navHtml);
	}
};

module.exports = navSide;